﻿
Imports System
Imports System.Drawing.Color
Imports System.Drawing.SystemColors

Public Class Form1

	Dim random1 As New Random,
		min As Integer = 0,
		max As Integer = 1,
		lastNumber As Integer = Nothing,
		nextNumber As Integer = 0,
		isError As Boolean = False,
		theme As String = ""

	Private Sub NumberChanged(sender As Object, e As EventArgs) _
	Handles MinNumber.ValueChanged, MaxNumber.ValueChanged

		min = MinNumber.Value
		max = MaxNumber.Value

		If Not min < max Then
			isError = True
			ErrorLabel.Show()
		Else
			isError = False
			ErrorLabel.Hide()
		End If

	End Sub

	Private Sub Generate(sender As Object, e As EventArgs) _
	Handles GenerateButton.Click

		If isError Then Exit Sub

		Do
			nextNumber = random1.Next(min, max + 1)
		Loop While RepeatCheck.Checked AndAlso nextNumber = lastNumber

		TextBox1.Text = nextNumber
		lastNumber = nextNumber

	End Sub

	Private Sub LinkToHomePage(sender As Object, e As LinkLabelLinkClickedEventArgs) _
	Handles HomePageLink.LinkClicked

		Process.Start("https://gitee.com/l_mc/Randomizer")

	End Sub

	Private Sub ThemeChanged(sender As Object, e As EventArgs) _
	Handles ThemeCombo.SelectedIndexChanged

		theme = ThemeCombo.SelectedItem

		If theme = "Normal" Then

			Me.BackColor = Control
			Me.ForeColor = ControlText

			MinNumber.BackColor = Window
			MinNumber.ForeColor = WindowText

			MaxNumber.BackColor = Window
			MaxNumber.ForeColor = WindowText

			TextBox1.BackColor = Control
			TextBox1.ForeColor = WindowText

			ThemeCombo.BackColor = Window
			ThemeCombo.ForeColor = WindowText

			ErrorLabel.ForeColor = Red

			GenerateButton.BackColor = Control
			GenerateButton.ForeColor = ControlText

			HomePageLink.LinkColor = Blue

		ElseIf theme = "Dark" Then

			Me.BackColor = ControlText
			Me.ForeColor = Control

			MinNumber.BackColor = WindowText
			MinNumber.ForeColor = Window

			MaxNumber.BackColor = WindowText
			MaxNumber.ForeColor = Window

			TextBox1.BackColor = ControlText
			TextBox1.ForeColor = Window

			ThemeCombo.BackColor = WindowText
			ThemeCombo.ForeColor = Window

			ErrorLabel.ForeColor = Red

			GenerateButton.BackColor = ControlDark
			GenerateButton.ForeColor = ControlText

			HomePageLink.LinkColor = CornflowerBlue

		ElseIf theme = "Creeper" Then

			Me.BackColor = LimeGreen
			Me.ForeColor = ControlText

			MinNumber.BackColor = FromArgb(0, 31, 0)
			MinNumber.ForeColor = Gainsboro

			MaxNumber.BackColor = FromArgb(0, 31, 0)
			MaxNumber.ForeColor = Gainsboro

			TextBox1.BackColor = FromArgb(0, 31, 0)
			TextBox1.ForeColor = Window

			ThemeCombo.BackColor = LimeGreen
			ThemeCombo.ForeColor = WindowText

			ErrorLabel.ForeColor = DarkMagenta

			GenerateButton.BackColor = FromArgb(0, 31, 0)
			GenerateButton.ForeColor = Control

			HomePageLink.LinkColor = Blue

		End If

	End Sub

End Class
